Skip to content

fix(mobile): validate device.setPermission's name and state before the device call - #1605

Merged
okwasniewski merged 5 commits into
e2e-inc:mainfrom
karolkulesza:fix/set-permission-validate
Nov 7, 2026
Merged

okwasniewski merged 5 commits into
e2e-inc:mainfrom
karolkulesza:fix/set-permission-validate

Conversation

@karolkulesza

@karolkulesza karolkulesza commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What and why

  • device.openApp({ permissions }) checks permission names and states, but device.setPermission sent them straight to agent-device, so 'camra' failed as ENGINE_FAILURE ("settings permission requires a target: ...").
  • setPermission now runs the same check first: a bad name (naming the nearest one), a bad state, or a missing state is INVALID_ARGUMENT, and no device command is sent.
  • The reference gets a Throws table for setPermission.

Issue

Fixes #1603

Verified

Ran it locally: yes - built CLI on an iPhone 16 simulator (iOS 18.5), scratch target on com.apple.Preferences, plus pnpm --filter @e2e-dev/mobile run test and pnpm check.

main this branch
setPermission('camra', 'grant') ENGINE_FAILURE: permission camra grant failed: settings permission requires a target: all|camera|... INVALID_ARGUMENT: device.setPermission has unknown key "camra"; did you mean "camera"?
setPermission('camera', 'allow') ENGINE_FAILURE: ... Invalid permission state: allow. Use <grant|deny|reset> ... INVALID_ARGUMENT: device.setPermission.camera must be one of grant, deny, reset, got "allow"
setPermission('camera', 'reset') passes passes

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

View guided diff

…e device call

device.setPermission sent any name and state straight to agent-device's
settings.update, so a typo such as 'camra' failed as ENGINE_FAILURE after a
device round trip ("settings permission requires a target: ..."). It now runs
the same check as device.openApp({ permissions }) first and refuses a bad
name (naming the nearest one), a bad state, or a missing state with
INVALID_ARGUMENT.
@github-actions github-actions Bot added the size:S Up to 29 changed lines, not counting tests, fixtures, translated docs, or the lockfile label Nov 6, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread packages/mobile/src/surface.ts Resolved
Comment thread .changeset/set-permission-validate.md Resolved
A symbol name was skipped by the map check, and an object whose toString()
returned "camera" passed as camera while the object itself reached
settings.update. setPermission now refuses any non-string name with
INVALID_ARGUMENT. The step label goes through String() so a symbol reaches
that check instead of throwing a TypeError while the label is built.

The changeset now says which error names the nearest permission (a bad name)
and which lists the valid states (a bad or missing state).

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 4 files (changes from recent commits).

View guided diff | Re-trigger cubic

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by Claude Code on behalf of maintainers.

The fix is right: it reuses assertPermissions with the same DEVICE_PERMISSIONS / PERMISSION_STATES as openApp({ permissions }), so the lists can't drift. Tests are real (removing the call, the undefined guard, or the whole block each fails a test). CI green. Two shape asks before it's ready:

Must fix

  1. packages/mobile/src/surface.ts:840-849 - wrapping one argument as { [permission]: state } to reuse the map validator is what forces the extra typeof and undefined guards, and line 848 hand-copies the must be one of ..., got template from line 359. Add one assertPermission(label, name, state, code) next to assertPermissions (string in DEVICE_PERMISSIONS with nearest-name suggestion, state in PERMISSION_STATES, undefined refused), have the assertPermissions loop call it per entry, and make setPermission a single call. One function owns the message.
  2. Drop the symbol / { toString } hardening (surface.ts:839-845, String(permission) in device.ts:323, the symbol loop in engine.test.ts). It guards deliberate as never callers, not the #1603 typo, and sibling setters (setNetwork, setAppearance) don't do it. A typeof name === 'string' check inside fix 1 covers it.

Nits

  • Message reads has unknown key "camra" for a positional arg; something like device.setPermission permission "camra" is unknown; did you mean "camera"? falls out of fix 1.
  • Changeset can be one line: "device.setPermission rejects an unknown permission name or state with INVALID_ARGUMENT, naming the nearest permission for a typo."

@github-actions github-actions Bot removed the size:S Up to 29 changed lines, not counting tests, fixtures, translated docs, or the lockfile label Nov 7, 2026
@karolkulesza

Copy link
Copy Markdown
Contributor Author

Thanks @okwasniewski, done in 191b1ac:

  1. assertPermission(label, name, state, code) now sits next to assertPermissions and owns the messages: a name must be a string in DEVICE_PERMISSIONS (nearest name suggested), and the state must be in PERMISSION_STATES, undefined refused. The assertPermissions loop calls it for each entry with a state, and setPermission is one call to it.
  2. Dropped the symbol / { toString } hardening: String(permission) in device.ts and the symbol loop in the test are gone. The typeof name === 'string' check inside assertPermission covers a non-string (the test now passes 42).

Changeset is the one line you suggested.

On the message nit: the typo message still reads device.setPermission has unknown key "camra"; did you mean "camera"?. The suggestion comes from rejectUnknownKeys, because didYouMean isn't exported from e2e/engine and the mobile engine imports only from there. Exporting it would change the core API and the peer range, so I left it out of this PR. Happy to do it as a follow-up if you want the positional wording.

pnpm --filter @e2e-dev/mobile typecheck, oxlint and tests/unit/engine.test.ts pass locally.

@github-actions github-actions Bot added the size:M Up to 99 changed lines, not counting tests, fixtures, translated docs, or the lockfile label Nov 7, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 4 files (changes from recent commits).

View guided diff | Re-trigger cubic

@okwasniewski

Copy link
Copy Markdown
Member

Automated review by Claude Code on behalf of maintainers.

Re-review at 68e1541. Both asks from the last round are done, thanks.

Asks

  1. assertPermission(label, name, state, code) sits next to assertPermissions, the map loop calls it per entry, and setPermission is one call. Good.
  2. Symbol/toString hardening is gone (String(permission) in device.ts, the symbol loop in the test). The remaining typeof name !== 'string' guard is fine: without it a symbol name would get past rejectUnknownKeys silently.

Changeset is one line. Docs table matches the other Throws tables.

Non-blocking

  • A bad positional name still reads device.setPermission has unknown key "camra"; did you mean "camera"?, since it reuses rejectUnknownKeys. Fine to keep. Better wording would mean exporting didYouMean from e2e/engine, which isn't worth it here.
  • The assertPermission JSDoc calls it "the one owner of the permission messages", but the unknown-name message comes from rejectUnknownKeys and the plain-object one stays in assertPermissions. Could drop that sentence.

Checked

  • @e2e-dev/mobile vitest 500/500, tsc --noEmit, lint, dead-code, changeset-bumps, docs error check: clean.
  • Mutations (dist rebuilt each time), 7 of 8 caught: removing the type check, name check, state check, map loop call, undefined skip, the setPermission call, or narrowing the state check each fails a test. Swapping the error class in permissionError survives, but that code only moved, so the gap predates this PR.
  • No em/en dashes in new text.

LGTM once CI is green.

This was an automated review.

@okwasniewski
okwasniewski dismissed their stale review November 7, 2026 10:11

Addressed in 191b1ac, see re-review.

@okwasniewski okwasniewski added the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Nov 7, 2026

@okwasniewski okwasniewski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: asks done, see comment.

@okwasniewski
okwasniewski added this pull request to the merge queue Nov 7, 2026
Merged via the queue into e2e-inc:main with commit 62d3c66 Nov 7, 2026
24 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. size:M Up to 99 changed lines, not counting tests, fixtures, translated docs, or the lockfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mobile: device.setPermission sends an unknown permission name or state to the device instead of failing with INVALID_ARGUMENT

2 participants